# _*_ coding: utf-8 _*_
# @Time : 2024-01-16 22:44
# @Author : wf

# 安装 lxml:  pip install lxml

from lxml import etree

html_tree: etree._ElementTree = etree.parse('01_xpath的基本使用.html')

# <class 'lxml.etree._ElementTree'>
# print(type(html_tree))

# li_list = html_tree.xpath('//body/ul/li')
li_list = html_tree.xpath('//body//li')

print(len(li_list))

# 查询有属性值的标签
# text() 标签文本
# li_list = html_tree.xpath('//ul//li[@id]/text()')
# print(li_list)
# print(len(li_list))


# li_list = html_tree.xpath('//ul//li[@id="l1"]/text()')
# print(li_list)
# print(len(li_list))


# li_list = html_tree.xpath('//ul//li[@id="l1"]/@class')
# print(li_list)
# print(len(li_list))


# li_list = html_tree.xpath('//ul//li[contains(@id, "l")]/text()')
# print(li_list)
# print(len(li_list))


# li_list = html_tree.xpath('//ul//li[starts-with(@id, "c")]/text()')
# print(li_list)
# print(len(li_list))


# li_list = html_tree.xpath('//ul//li[@id="l1" and @class="c1"]/text()')
# print(li_list)
# print(len(li_list))


li_list = html_tree.xpath('//ul//li[@id="l1"]/text() | //ul//li[@id="l2"]/text()')
print(li_list)
print(len(li_list))
